package com.java.gui;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class WindowEventTest {
	private JFrame frame;
	public WindowEventTest(){
		frame=new JFrame("WindowEventTest!!!");
	}
	public void showMe(){
		addEventHandler();
		frame.setSize(400, 300);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	}
	public void addEventHandler(){
		frame.addWindowListener(new WindowAdapter(){

			public void windowClosing(WindowEvent e) {
				super.windowClosing(e);
				super.windowClosed(e);
				int i=JOptionPane.showConfirmDialog(frame, "你确定要退出吗？","标准对话框",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
				if(i==JOptionPane.YES_OPTION){
					System.exit(0);
				}
			}

			
		});
	}
	
	public static void main(String[] args){
		new WindowEventTest().showMe();
	}
}
